﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;

namespace WindowsFormsApplicationColor
    {
    public partial class Form1 : Form
        {
        public Form1()
            {
            InitializeComponent();
            }

        private void button1_Click(object sender, EventArgs e)
            {
            Debug.WriteLine("bouton1 : " + this.button1.Location);
            this.setColor(this.button1);
            }

        private void button2_Click(object sender, EventArgs e)
            {
            Debug.WriteLine("bouton2 : " + this.button2.Location);
            this.setColor(this.button2);
            }

        private void button3_Click(object sender, EventArgs e)
            {
            Debug.WriteLine("bouton3 : "+this.button3.Location);
            this.setColor(this.button3);
            }

        private Color getColor()
            {
            Random random = new Random();
            return Color.FromArgb(random.Next(0,254),random.Next(0,254),random.Next(0,254));
            }

        private void setColor(Button button)
            {
            button.BackColor = this.getColor();
            this.BackColor = button.BackColor;
            }
        }   
    }
